<template>
  <div class="custome-table">
    <el-dialog
      title="任务详情"
      :visible="dialogVisibleTest"
      @open="init"
      @close="closeDialog"
    >
      <el-form
        ref="form"
        :model="dataForm"
      >
        <div class="custom-table">
          <table>
            <tr>
              <th width="100">任务名称</th>
              <th colspan="2">
                {{ dataForm.taskName }}
              </th>
              <th>任务编号</th>
              <th colspan="3">
                {{ dataForm.num }}
              </th>
            </tr>
            <tr>
              <th width="100">项目部</th>
              <th colspan="2">
                {{ dataForm.projectDepartmentName }}
              </th>
              <th>发布人</th>
              <th colspan="3">
                {{ dataForm.publisherName }}
              </th>
            </tr>
            <tr>
              <th width="100">责任人</th>
              <th colspan="2">
                {{ dataForm.responsibleName }}
              </th>
              <th>协助人</th>
              <th colspan="3">
                {{ dataForm.processPersonnelName }}
              </th>
            </tr>
            <tr>
              <th width="100">任务类型</th>
              <th colspan="2">
                {{ getDictLabel('e008', dataForm.taskType) }}
              </th>
              <th>任务内容</th>
              <th colspan="3">
                {{ dataForm.taskContent }}
              </th>
            </tr>
            <tr>
              <th width="100">备注</th>
              <th colspan="2">
                {{ dataForm.remark }}
              </th>
              <th>完成时间</th>
              <th colspan="3">
                {{ parseTime(taskCompletionSituation.gmtModified, '{y}-{m}-{d}') }}
              </th>
            </tr>
            <tr>
              <th width="100">运维表单号</th>
              <th colspan="2">
                <template>
                  <div
                    v-for="(item, index) in formNoList"
                    :key="index + '_item'"
                    style="color:#0004ff;text-decoration:underline;cursor:pointer;"
                    @click="getForm(item)"
                  >{{ item }}</div>
                </template>
              </th>
              <th>任务完成描述</th>
              <th colspan="3">
                {{ taskCompletionSituation.operationContent }}
              </th>
            </tr>
            <tr>
              <th width="100">审核时间</th>
              <th colspan="2">
                {{ parseTime(auditResults.gmtModified, '{y}-{m}-{d}') }}
              </th>
              <th>任务状态</th>
              <th colspan="3">
                {{ getDictLabel('e009', dataForm.taskStatus) }}
              </th>
            </tr>
            <tr>
              <th width="100">意见</th>
              <th colspan="2">
                {{ auditResults.operationContent }}
              </th>
              <th>备注</th>
              <th colspan="3">
                {{ auditResults.remark }}
              </th>
            </tr>
          </table>
        </div>
      </el-form>
    </el-dialog>
    <MaintenanceDetailDialog
      :dialog-visible="maintenanceDetailVisible"
      :obj="edit.obj"
      @closeDialog="maintenanceDetailVisible = false"
    />
  </div>
</template>

<script>
import { getDict } from '@/utils/dict'
import { getList } from '@/api/info/taskProcess'
import { getMaintenanceById } from '@/api/info/task'
import { getProjectPersonnel } from '@/utils/common'
import { getDictLabel, parseTime } from '@/utils'
import MaintenanceDetailDialog from '@/views/maintenanceManage/components/MaintenanceDetailDialog'

export default {
  name: 'Detail',
  components: {
    MaintenanceDetailDialog
  },
  props: {
    dialogVisibleTest: {
      type: Boolean,
      default: false
    },
    obj: {
      type: Object,
      default: () => {
      }
    }
  },
  data() {
    return {
      dataForm: {
        id: null,
        ids: [],
        num: null,
        taskName: null,
        taskContent: null,
        taskType: null,
        taskStatus: null,
        projectDepartmentId: '',
        startTime: null,
        remark: null,
        publisherId: '',
        responsibleId: '',
        helperId: [],
        maintenanceId: [],
        statusDescription: null,
        formNo: null
      },
      edit: {
        visible: false,
        obj: null
      },
      formNoList: [],
      maintenanceDetailVisible: false,
      taskTypes: [],
      projectDepartments: [],
      publishers: [],
      responsibles: [],
      helpers: [],
      maintenances: [],
      taskStatus: [],
      taskCompletionSituation: {},
      auditResults: {},
      auditOrHandle: null,
      auditShow: false
    }
  },
  created() {
    this.taskTypes = getDict('e008')
    this.taskTypes.shift()
    this.taskStatus = getDict('e009')
  },
  methods: {
    getDictLabel, parseTime,
    init() {
      this.clearData()
      this.dataForm = this.obj
      if (this.dataForm.formNo) {
        this.formNoList = this.dataForm.formNo.split(',')
      }
      this.getTaskProcess()
    },
    getList(pid) {
      getProjectPersonnel({ 'pid': pid }).then(res => {
        this.options = res.data.row
      })
    },
    getForm(no) {
      getMaintenanceById(no).then(value => {
        this.edit.obj = { 'id': value.data.obj.id }
        this.maintenanceDetailVisible = true
      })
    },
    getTaskProcess() {
      getList({ 'taskId': this.dataForm.id }).then(res => {
        res.data.list.forEach(item => {
          if (item.taskProcessOperationType === 'e010_02') {
            this.taskCompletionSituation = item
          } else if (item.taskProcessOperationType === 'e010_03') {
            this.auditResults = item
          }
        })
      })
    },
    clearData() {
      this.dataForm = {
        id: null,
        ids: [],
        num: null,
        taskName: null,
        taskContent: null,
        taskType: null,
        taskStatus: null,
        projectDepartmentId: '',
        startTime: null,
        remark: null,
        publisherId: '',
        responsibleId: '',
        helperId: [],
        maintenanceId: [],
        statusDescription: null,
        formNo: null
      }
      this.formNoList = []
      this.taskTypes = []
      this.projectDepartments = []
      this.publishers = []
      this.responsibles = []
      this.helpers = []
      this.maintenances = []
      this.taskStatus = []
      this.taskCompletionSituation = {}
      this.auditResults = {}
      this.auditOrHandle = null
      this.auditShow = false
    },
    closeDialog() {
      this.$emit('closeDialog')
      this.clearData()
      this.$refs['form'].clearValidate()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
